package com.js.purs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.js.purs.domain.PurProdPlanFile;
import com.js.purs.service.IPurProdPlanFileService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购计划附件Controller
 * 
 * @author lzq
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/planFiles")
public class PurProdPlanFileController extends BaseController
{
    @Autowired
    private IPurProdPlanFileService purProdPlanFileService;

    /**
     * 查询采购计划附件列表
     */
    @RequiresPermissions("planFiles:planFiles:list")
    @GetMapping("/list")
    public TableDataInfo list(PurProdPlanFile purProdPlanFile)
    {
        startPage();
        List<PurProdPlanFile> list = purProdPlanFileService.selectPurProdPlanFileList(purProdPlanFile);
        return getDataTable(list);
    }

    /**
     * 导出采购计划附件列表
     */
    @RequiresPermissions("planFiles:planFiles:export")
    @Log(title = "采购计划附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurProdPlanFile purProdPlanFile)
    {
        List<PurProdPlanFile> list = purProdPlanFileService.selectPurProdPlanFileList(purProdPlanFile);
        ExcelUtil<PurProdPlanFile> util = new ExcelUtil<PurProdPlanFile>(PurProdPlanFile.class);
        util.exportExcel(response, list, "采购计划附件数据");
    }

    /**
     * 获取采购计划附件详细信息
     */
    @RequiresPermissions("planFiles:planFiles:query")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") String fileId)
    {
        return success(purProdPlanFileService.selectPurProdPlanFileByFileId(fileId));
    }

    /**
     * 新增采购计划附件
     */
    @RequiresPermissions("planFiles:planFiles:add")
    @Log(title = "采购计划附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurProdPlanFile purProdPlanFile)
    {
        return toAjax(purProdPlanFileService.insertPurProdPlanFile(purProdPlanFile));
    }

    /**
     * 修改采购计划附件
     */
    @RequiresPermissions("planFiles:planFiles:edit")
    @Log(title = "采购计划附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurProdPlanFile purProdPlanFile)
    {
        return toAjax(purProdPlanFileService.updatePurProdPlanFile(purProdPlanFile));
    }

    /**
     * 删除采购计划附件
     */
    @RequiresPermissions("planFiles:planFiles:remove")
    @Log(title = "采购计划附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable String[] fileIds)
    {
        return toAjax(purProdPlanFileService.deletePurProdPlanFileByFileIds(fileIds));
    }
}
